home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / optivc32 / mcfstd.h < prev    next >
C/C++ Source or Header  |  1999-03-06  |  31KB  |  590 lines

  1. /*  MCFstd.h
  2.  
  3.   matrix management functions:
  4.   manipulations on matrices of data type "fComplex"
  5.   (single-precision complex numbers)
  6.  
  7.   Copyright (c) 1996-1999 by Martin Sander
  8.   All Rights Reserved.
  9. */
  10.  
  11. #if !defined( __MATLIB_H )
  12.    #include <MatLib.h>
  13. #endif
  14. #if !defined( __VCFSTD_H )
  15.    #include <VCFstd.h>
  16. #endif
  17.  
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21.  
  22. /*************   Dynamic Generation of Matrices   ************************/
  23.  
  24. cfMatrix __vf  MCF_matrix(  unsigned ht, unsigned len );
  25. cfMatrix __vf  MCF_matrix0( unsigned ht, unsigned len );
  26.     /*  notice that, in the memory model HUGE,
  27.         neither len nor ht may exceed 4095            */
  28.  
  29. /***************************************************************************
  30.  *  The following definitions ensure compatibility between dynamically     *
  31.  *  and statically allocated matrices. The definitions are somewhat        *
  32.  *  cumbersome, but the result for you is that you need not care about     *
  33.  *  the differences between the two types.                                 *
  34.  *  (Internally, the address of the first element of any matrix is needed; *
  35.  *  the expression "MA[0]" is evaluated in a different way for both types, *
  36.  *  but yields in either case the correct address to be passed to the      *
  37.  *  function you wish to call.)                                            *
  38.  *  Only in the rare case that you need to pass the address of one of      *
  39.  *  these functions as an argument to another function, you have to use    *
  40.  *  the actual run-time functions defined further below. Be careful with   *
  41.  *  this: future development of compilers may allow us to avoid this un-   *
  42.  *  handy scheme of macros. So future versions of MatrixLib may no longer  *
  43.  *  use these run-time names.                                              *
  44.  ***************************************************************************/
  45.  
  46.  
  47. /***  Addressing single elements of dynamically allocated matrices: ******
  48.      These two functions are for compatibility with Pascal
  49.      (where elements of dynamically allocated matrices are not directly
  50.      accessible), and for getting around the pointer arithmetics bug in
  51.      some versions of Borland C++.                                     */
  52.  
  53. #define MCF_Pelement( MA, ht, len, m, n ) MCFPelement( MA[0], ht, len, m, n )
  54.                      /* returns a pointer to MA[m][n]. */
  55. #define MCF_element( MA, ht, len, m, n ) *MCFPelement( MA[0], ht, len, m, n )
  56.                      /* dereferenced pointer */
  57.  
  58.  /****************  Initialization  ***************************************
  59.  
  60.     To initialize all elements of a matrix with the same value,
  61.     or to perform arithmetic operations on all elements simultaneously,
  62.     refer to the functions of VectorLib, declared in <VCFstd.h>, <VCFmath.h>.
  63.     In order to use the VectorLib functions, utilize the feature that
  64.     the whole matrix occupies one contiguous area in memory: pass the
  65.     address of the first row to the desired vector function, the size
  66.     of the "vector" being len * ht.
  67.     For example, initialize all elements of the matrix MA with {1.0, 0.0}
  68.     (this is *NOT* the identity matrix)  by calling
  69.         VCF_equ1( MA[0], len * ht );
  70. */
  71.  
  72. #define MCF_equ1( MA, len )                MCFequ1( MA[0], len )
  73.                        /* this is the identity matrix */
  74. #define MCF_outerprod( MA, X, Y, ht, len ) MCFouterprod( MA[0], X, Y, ht, len )
  75.                        /* sizX=ht, sizY=len */
  76. #define MCF_Row_equC( MA, ht, len, iRow, C ) \
  77.                                         MCFRow_equC( MA[0], ht, len, iRow, C )
  78. #define MCF_Col_equC( MA, ht, len, iCol, C ) \
  79.                                         MCFCol_equC( MA[0], ht, len, iCol, C )
  80. #define MCF_Dia_equC( MA, len, C )       MCFDia_equC( MA[0], len, C )
  81.  
  82. #define MCF_Row_equV( MA, ht, len, iRow, X ) \
  83.                                         MCFRow_equV( MA[0], ht, len, iRow, X )
  84. #define MCF_Col_equV( MA, ht, len, iCol, X ) \
  85.                                         MCFCol_equV( MA[0], ht, len, iCol, X )
  86. #define MCF_Dia_equV( MA, len, X )       MCFDia_equV( MA[0], len, X )
  87.  
  88. #define MCF_equM( MB, MA, ht, len )  VCF_equV( MB[0], MA[0], ((ui)(len))*(ht) )
  89.  
  90. #define MCF_UequL( MA, len ) MCFUequL( MA[0], len )
  91. #define MCF_LequU( MA, len ) MCFLequU( MA[0], len )
  92.          /* copy lower-diagonal elements into upper-diagonal
  93.            (or vice versa) by index-reflection, so as to
  94.            get a symmetric matrix    */
  95.  
  96.             /* data-type conversions:  */
  97. #define M_CEtoCF( MCF, MCE, ht, len ) V_CEtoCF( MCF[0], MCE[0], ((ui)ht)*len )
  98. #define M_CFtoCE( MCE, MCF, ht, len ) V_CFtoCE( MCE[0], MCF[0], ((ui)ht)*len )
  99. #define M_CDtoCF( MCF, MCD, ht, len ) V_CDtoCF( MCF[0], MCD[0], ((ui)ht)*len )
  100. #define M_CFtoCD( MCD, MCF, ht, len ) V_CFtoCD( MCD[0], MCF[0], ((ui)ht)*len )
  101.  
  102. /********  Extracting a submatrix and copying a submatrix back  *********/
  103.  
  104. #define MCF_submatrix( MSub, subHt, subLen, \
  105.                        MSrce, srceHt, srceLen, \
  106.                        firstRowInCol, sampInCol, firstColInRow, sampInRow ) \
  107.                MCFsubmatrix(  MSub[0], subHt, subLen, \
  108.                               MSrce[0], srceHt, srceLen, \
  109.                               firstRowInCol, sampInCol, firstColInRow, sampInRow )
  110.  
  111. #define MCF_submatrix_equM( MDest, destHt, destLen, \
  112.                             firstRowInCol, sampInCol, firstColInRow, sampInRow, \
  113.                             MSrce, srceHt, srceLen ) \
  114.                MCFsubmatrix_equM(  MDest[0], destHt, destLen, \
  115.                              firstRowInCol, sampInCol, firstColInRow, sampInRow, \
  116.                              MSrce[0], srceHt, srceLen )
  117.  
  118. /*****   Extracting a single row or a single column or the diagonal  ******
  119.  *       and storing it into a vector                                     */
  120.  
  121. #define MCF_Row_extract( Y, MA, ht, len, iRow ) \
  122.                                      MCFRow_extract( Y, MA[0], ht, len, iRow )
  123. #define MCF_Col_extract( Y, MA, ht, len, iCol ) \
  124.                                      MCFCol_extract( Y, MA[0], ht, len, iCol )
  125. #define MCF_Dia_extract( Y, MA, len ) MCFDia_extract( Y, MA[0], len )
  126.  
  127.  
  128. /*****************    Basic arithmetic operations *********************
  129.                       performed on one single row,
  130.                       or one single column of any matrix,
  131.                       or on the diagonal of a square matrix
  132.  
  133.     Note: In contrast to the analogous VectorLib functions, the operations
  134.     are performed in-place, i.e. the input matrix itself is changed  */
  135.  
  136. #define MCF_Row_addC( MA, ht, len, iRow, C ) \
  137.                                      MCFRow_addC( MA[0], ht, len, iRow, C )
  138. #define MCF_Col_addC( MA, ht, len, iCol, C ) \
  139.                                      MCFCol_addC( MA[0], ht, len, iCol, C )
  140. #define MCF_Dia_addC( MA, len, C )   MCFDia_addC( MA[0], len, C )
  141.  
  142. #define MCF_Row_addV( MA, ht, len, iRow, X ) \
  143.                                      MCFRow_addV( MA[0], ht, len, iRow, X )
  144. #define MCF_Col_addV( MA, ht, len, iCol, X ) \
  145.                                      MCFCol_addV( MA[0], ht, len, iCol, X )
  146. #define MCF_Dia_addV( MA, len, X )   MCFDia_addV( MA[0], len, X )
  147.  
  148. #define MCF_Row_subC( MA, ht, len, iRow, C ) \
  149.                                      MCFRow_addC( MA[0], ht, len, iRow, (-C) )
  150. #define MCF_Col_subC( MA, ht, len, iCol, C ) \
  151.                                      MCFCol_addC( MA[0], ht, len, iCol, (-C) )
  152. #define MCF_Dia_subC( MA, len, C )   MCFDia_addC( MA[0], len, (-C) )
  153.  
  154. #define MCF_Row_subV( MA, ht, len, iRow, X ) \
  155.                                      MCFRow_subV( MA[0], ht, len, iRow, X )
  156. #define MCF_Col_subV( MA, ht, len, iCol, X ) \
  157.                                      MCFCol_subV( MA[0], ht, len, iCol, X )
  158. #define MCF_Dia_subV( MA, len, X )   MCFDia_subV( MA[0], len, X )
  159.  
  160. #define MCF_Row_subrC( MA, ht, len, iRow, C ) \
  161.                                      MCFRow_subrC( MA[0], ht, len, iRow, C )
  162. #define MCF_Col_subrC( MA, ht, len, iCol, C ) \
  163.                                      MCFCol_subrC( MA[0], ht, len, iC